package com.example.shop_2210.adapter

import android.util.Log
import android.widget.TextView
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.launcher.ARouter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.CategoryEntity
import com.example.base.entity.Child
import com.example.shop_2210.R
import com.example.shop_2210.utils.GlideUtils
import kotlin.math.log

class TwoAdapter:BaseQuickAdapter<CategoryEntity,BaseViewHolder>(R.layout.item_two) {
    override fun convert(holder: BaseViewHolder, item: CategoryEntity) {
        holder.setText(R.id.title,"------${item.name}------")
        val rv = holder.getView<RecyclerView>(R.id.rv_two_child)//找到rv
        val twoChildAdapter = TwoChildAdapter()//找到适配器
        twoChildAdapter.data.addAll(item.child)//添加数据
        rv.adapter = twoChildAdapter//绑定
        rv.layoutManager = GridLayoutManager(context,3)
    }
}

class TwoChildAdapter:BaseQuickAdapter<Child,BaseViewHolder>(R.layout.item_tow_child){
    override fun convert(holder: BaseViewHolder, item: Child) {
        GlideUtils.loadCircleImage(context,item.extra,holder.getView(R.id.child_image))
        holder.setText(R.id.child_name,item.name)
        //点击事件
        holder.itemView.setOnClickListener {
            ARouter.getInstance().build("/app/CategoryDetailActivity")
                .withInt("cid",item.id)
                .withString("cname",item.name)
                .navigation()
            //显示点击的是哪一个
            //Log.d("sss", "convert: ${holder.getView<TextView>(R.id.child_name).text.toString()}")
        }
    }

}